package com.cris.helper;

import com.cris.model.Product;
import com.cris.model.ProductType;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * Created by owen on 2017/4/16.
 */
public class MapHelper {
    private static Product product = new Product();
    private static ProductType productType = new ProductType();


    /**
     * put product
     */
    public static HashMap<String,Object> put(Object entity){
        HashMap<String,Object> map = new HashMap<>();
        if(entity instanceof Product){
            product = (Product)entity;
            Date date=new Date();
            DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time=format.format(date);
            Subject subject = SecurityUtils.getSubject();
            map.put("name",product.getName());
            map.put("handler",subject.getPrincipal());
            map.put("time",time);
            map.put("typeid",product.getTypeid());
            map.put("guarantee",product.getGuarantee());
            map.put("brand",product.getBrand());
            map.put("remark",product.getRemark());
            return map;

        }else if (entity instanceof ProductType){
            productType = (ProductType)entity;
            map.put("name",productType.getName());
            map.put("parentid",productType.getParentid());
            map.put("remark",product.getRemark());
            return map;
        }
        else return null;
    }
}
